$(function(){

	// Rounded

	var html = document.documentElement,
		htmls = html.style,
		brs = (html) ? (typeof htmls.borderRadius == 'string' ||
			typeof htmls.MozBorderRadius == 'string' ||
			typeof htmls.WebkitBorderRadius == 'string' ||
			typeof htmls.KhtmlBorderRadius == 'string') ? 1 : 0 : 0;

	if(!brs) html.id = 'br';

	// Scroll

	$('a[href*=#]').each(function(){
		var locationPath = filterPath(location.pathname);
		var thisPath = filterPath(this.pathname) || locationPath;
		if(locationPath == thisPath && (location.hostname == this.hostname || !this.hostname) && this.hash.replace(/#/,'')){
			var $target = $(this.hash),target = this.hash;
			if(target){
				var targetOffset = $target.offset().top;
				$(this).click(function(event){
					event.preventDefault();
					var frame = ($.browser.safari) ? $('body') : $('html'); // Dirty fix,i know
					frame.animate({scrollTop:targetOffset},400,function(){
						location.hash = target;
					});
				});
			}
		}
	});

	function filterPath(string){
		return string.replace(/^\//,'').replace(/\/$/,'');
	}

	// Tweets

	$.fn.tweets = function(q){
		var list = $(this);
		var url = 'http://search.twitter.com/search.json?q=%23'+ q +'&rpp=20&callback=?';
		$.getJSON(url,function(data){
			$.each(data.results,function(i,item){
				var user = item.from_user;
				var image = item.profile_image_url;
				var text = item.text;
					text = text.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/,function(str){return str.link(str)});
					text = text.replace(/[\#]+([A-Za-z0-9-_]+)/ig,function(str){return str.link('http://twitter.com/search?q=%23'+str.substr(1))});
				list.append('<li><a href="http://twitter.com/'+ user +'" title="'+ user +'"><img src="'+ image + '"></a>' + text +'</li>');
			});
		});
	}

	$('#twitter ul').tweets('wstdays');

	// Map

	$.fn.map = function(latitude,longitude){
		if(GBrowserIsCompatible()){
			var wst = new GIcon();
				wst.image = 'i/map-logo.png';
				wst.shadow = 'i/map-shadow.png';
				wst.iconSize = new GSize(64,63);
				wst.shadowSize = new GSize(124,65);
				wst.iconAnchor = new GPoint(32,63);
			var map = new GMap2(document.getElementById(this.selector.substr(1)));
				map.setCenter(new GLatLng(latitude,longitude),14);
				map.addControl(new GSmallMapControl());
				map.addControl(new GMapTypeControl());
				map.removeMapType(G_SATELLITE_MAP);
				map.addOverlay(new GMarker(new GLatLng(latitude,longitude),wst));
		}
	}

	$('#map').map(53.914349,27.551222);
	
	window.onerror = function(){
		return true;
	}

});